import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/theme/gt_colors_v3.dart';
import 'package:lib_uikit/widgets/bottomsheet/gt_bottom_sheet.dart';

import '../text/gt_text.dart';

/// @Title   弹出文字列表bottomsheet
/// @Author: bryce
/// @CreateDate: 2023年10月18日16:09:54
Future<int?> showTextListBottomSheet(
  context, {
  required List<String> textList,
  int selectedIndex = -1,
  double? maxHeight, // bottomSheet最大高度
  double? minHeight, // bottomSheet最小高度
  // 下面的数据建议使用默认数值，符合规范
  double topPadding = 24, // child上边距
  double bottomPadding = 24, // child下边距，不是指cancel按钮下的边距
  double leftPadding = 16,
  double rightPadding = 16,
  double topRadius = 8.0, // bottomSheet上方圆角
  bool showBottomCancel = true, // 是否展示底部取消按钮
  bool showTopRightClose = false, // 是否展示右上角关闭按钮
  String? title,
}) async {
  return showGTBottomSheet(context,
      maxHeight: maxHeight,
      minHeight: minHeight,
      topPadding: topPadding,
      bottomPadding: bottomPadding,
      leftPadding: leftPadding,
      rightPadding: rightPadding,
      topRadius: topRadius,
      showBottomCancel: showBottomCancel,
      showTopRightClose: showTopRightClose,
      title: title,
      child: ListView.separated(
        shrinkWrap: true,
        physics: const BouncingScrollPhysics(),
        itemCount: textList.length,
        separatorBuilder: (BuildContext context, int index) => const SizedBox(height: 8),
        itemBuilder: (BuildContext context, int index) {
          bool isSelected = index == selectedIndex;
          return GestureDetector(
            onTap: () => Navigator.pop(context, index),
            behavior: HitTestBehavior.opaque,
            child: Container(
              alignment: Alignment.center,
              height: 44,
              decoration: BoxDecoration(
                  color: isSelected ? GTColorsV3.neutral2.color : GTColorsV3.card6.color,
                  borderRadius: BorderRadius.circular(3)),
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 16),
                child: GTText(
                  textList[index],
                  style: TextStyle(
                      color: isSelected ? GTColorsV3.text5.color : GTColorsV3.text1.color,
                      fontSize: 14,
                      fontWeight: FontWeight.w500),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ),
          );
        },
      ));
}
